﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class YinHang : MonoBehaviour
{
    private float spendTime;
    int hour;//时钟
    int minute;//分钟
    int second;//秒钟

    Animator ani;
    int addone = 10;
    int addtwo = 10;

    // Start is called before the first frame update
    void Start()
    {
        //string str = LoginPanel.Showtetx();
        ani = GameObject.Find("Canvas").transform.Find("银行面板/领取金币").gameObject.GetComponent<Animator>();
        ani.speed = 0;
        MySqlAccess.OpenSql();
        MySqlAccess.QueryGold();
        GameObject.Find("Canvas").transform.Find("银行面板/领取金币").gameObject.GetComponent<Button>().onClick.AddListener(delegate
        {
            if (Time.time >= addone)
            {
                MySqlAccess.gold += 100;
                MySqlAccess.UpdateInto("shop", new string[] { "gold" }, new string[] { MySqlAccess.gold.ToString() }, "id", LoginPanel.Showtetx());
                GameObject.Find("Canvas").transform.Find("个人信息/金币数值").gameObject.GetComponent<Text>().text = MySqlAccess.QueryGold().ToString();
                addone += 10;
                ani.speed = 0;
            }
        });
    }

    // Update is called once per frame
    void Update()
    {
        TimeCycle();
        if (Time.time >= addone-1)
        {
            ani.speed = 1;
        }
    }

    public void TimeCycle()
    {
        spendTime += Time.deltaTime;
        hour = (int)(spendTime / 3600);
        minute = (int)((spendTime - hour * 3600) / 60);
        second = (int)(spendTime - hour * 3600 - minute * 60);
        int m = (int)(9 - minute);//10分钟
        if (m >= 0)
        {
            int s = (int)(59 - second);
            if (s < 10)
            {
                GameObject.Find("Canvas").transform.Find("银行面板/领取金币/Text").gameObject.GetComponent<Text>().text = "领取金币 " + "0" + m.ToString() + ":" + "0" + s;
            }
            else
                GameObject.Find("Canvas").transform.Find("银行面板/领取金币/Text").gameObject.GetComponent<Text>().text = "领取金币 " + "0" + m.ToString() + ":" + s;
        }
    }
}
